package com.lib093.cn

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.os.PersistableBundle
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.lib093.rich.activity.PublishActivity
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity :AppCompatActivity() {
    var bundle : Bundle?=null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        button_publish.setOnClickListener(object:View.OnClickListener{
            override fun onClick(v: View?) {
                intent = Intent(this@MainActivity, PublishActivity::class.java)
                bundle?.let {intent.putExtras(it) }
                startActivityForResult(intent,100)
            }
        })
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == Activity.RESULT_OK){
            bundle = data?.extras;
            toast(data?.extras?.getSerializable("data").toString())
        }
    }
}
fun Context.toast(msg:String){
    Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
}